package com.example.natatorium_management.contorller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.natatorium_management.entity.Good;
import com.example.natatorium_management.result.restful.R;
import com.example.natatorium_management.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/good")
public class GoodController {
    @Autowired
    GoodService goodService;

    /**
     * 分页查询全部
     * @param current 1
     * @param size 1
     * @return 1
     */
    @GetMapping("/queryPage")
    public R<IPage<Good>> queryPage(int current, int size) {
        return goodService.queryPage(current,size);
    }

    /**
     * 更新商品
     * @param good ·1
     * @return ·1
     */
    @PutMapping ("/updateGood")
    public R<Good> updateGood(@RequestBody Good good){
        return goodService.updateGood(good);
    }

    /**
     *新增商品
     * @param good 1
     * @return 1
     */
    @PostMapping("/addGood")
    public R<Good> addGood(@RequestBody Good good){
        return goodService.addGood(good);
    }

    /**
     * 根据Id查询
     * @param goodId 1
     * @return 1
     */
    @GetMapping("/findGoodById/{goodId}")
    public R<Good> findGoodById(@PathVariable("goodId") int goodId){
        return goodService.findGoodById(goodId);
    }

    /**
     * 查找商品
     * @param good 1
     * @param current 1
     * @param size 1
     * @return 1
     */
    @PostMapping("/findGood")
    public R<IPage<Good>> findGood(@RequestBody Good good,@RequestParam int current,@RequestParam int size) {
        return goodService.findGood(good,current,size);
    }

    /**
     * 删除
     * @param id 1
     * @return 1
     */
    @DeleteMapping("/deleteGoodById/{goodId}")
    public R<Good> deleteGoodById(@PathVariable("goodId") int id){
        return goodService.deleteGoodById(id);
    }

    /**
     * 找订单里的商品
     * @param orderId 1
     * @return 1
     */
    @GetMapping("/findAllGood/{orderId}")
    public R<List<Good>> findAllGood(@PathVariable("orderId") Long orderId){
        return goodService.findAllGood(orderId);
    }
}
